package m2team.com.zuatet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Common {
	public static final String ROBOTO_REGULAR = "RobotoCondensed-Regular";
	public static final String ROBOTO_BOLD = "RobotoCondensed-Bold";
	public static final String RobotoCondensed_Light = "RobotoCondensed-Light";
	public static final String Roboto_Regular = "Roboto-Regular";
	public static final String CaviarDreams = "CaviarDreams";
	public static final String Pacifico = "Pacifico";
    public static final String COMMA_TOKEN = ",";
	
	public static ArrayList<Item> getMainItem(Context context) {
		 ArrayList<Item> items = new ArrayList<Item>();
		 items.add(new Item(context.getResources().getString(R.string.text), R.drawable.bg_1));
		 items.add(new Item(context.getResources().getString(R.string.symbol), R.drawable.bg_2));
		 items.add(new Item(context.getResources().getString(R.string.cau_doi), R.drawable.bg_3));
		 items.add(new Item(context.getResources().getString(R.string.game), R.drawable.bg_8));
		 items.add(new Item(context.getResources().getString(R.string.predict), R.drawable.bg_6));
		 items.add(new Item(context.getResources().getString(R.string.wallpaper), R.drawable.bg_5));
		 items.add(new Item(context.getResources().getString(R.string.live_wallpaper), R.drawable.bg_7));
		 items.add(new Item(context.getResources().getString(R.string.favorites), R.drawable.bg_4));
		 items.add(new Item(context.getResources().getString(R.string.favorites), R.drawable.bg_9));
		 return items;
	}
	

	public static void setFont(final Context context, final View v, String font) {
		try {
			if (v instanceof ViewGroup) {
				ViewGroup vg = (ViewGroup) v;
				for (int i = 0; i < vg.getChildCount(); i++) {
					View child = vg.getChildAt(i);
					setFont(context, child, font);
				}
			} else if (v instanceof TextView) {
				((TextView) v).setTypeface(Typeface.createFromAsset(
						context.getAssets(), "fonts/" + font + ".ttf"));
			}
		} catch (Exception e) {
		}
	}

    public static ArrayList<String> readFile(Context context, String fileName) {
        ArrayList<String> strings = new ArrayList<>();
        StringBuilder stringBuilder = new StringBuilder();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(
                    new InputStreamReader(context.getAssets().open(fileName)));

            // do reading, usually loop until end of file reading
            String mLine = reader.readLine();
            while (mLine != null) {
                stringBuilder.append(mLine);
                mLine = reader.readLine();
            }
            strings.add(stringBuilder.toString());
        } catch (IOException e) {
            //log the exception
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    //log the exception
                }
            }
        }
        return strings;
    }
}
